package CinemaDevelop;

import java.time.LocalDateTime;

public class TicketSeller extends User {
    public TicketSeller(String userName, String passWord, String telephoneNum) {
        super(userName, passWord, telephoneNum);
    }

    @Override
    public void login(String userName, String passWord) {
        if (userName.equals(super.userName) && passWord.equals(super.passWord)) {
            isLogged = true;
            System.out.println("登陆成功！售票员：" + userName + ",欢迎您！");
        } else {
            System.out.println("用户名或密码错误！请重新登录。");
        }
    }

    @Override
    public void sellTicket(Cinema cinema, String movieName, String roomType,
                           LocalDateTime time, int row, int line, String inform) {
        if (isLogged) {
            MovieSchedule schedule = CinemaDAO.findSchedule(movieName, roomType, time);
            if (schedule != null) {
                try {
                    CinemaDAO.bookSeat(schedule.getScheduleId(), row, line, inform);
                    schedule.getRoom().sc.add(row, line, inform);
                    System.out.println("出票成功！");
                } catch (Exception e) {
                    System.out.println("出票失败: " + e.getMessage());
                }
            } else {
                System.out.println("未找到匹配的排期！");
            }
        } else {
            System.out.println("无权限，请先进行登录！");
        }
    }

    @Override
    public void showMovieCasted(Cinema cinema) {
        if (isLogged) {
            for (MovieSchedule schedule : cinema.getMovieSchedules()) {
                schedule.getMovie().getMovieInform();
            }
        } else {
            System.out.println("无权限，请先进行登录！");
        }
    }

    @Override
    public void findMovie(Cinema cinema, String movieName, String roomType) {
        if (isLogged) {
            boolean found = false;
            for (MovieSchedule schedule : cinema.getMovieSchedules()) {
                if (schedule.getMovie().name.equals(movieName) && schedule.getRoom().type.equals(roomType)) {
                    found = true;
                    System.out.println("放映厅：" + schedule.getRoom().type +
                            "  总座位数：" + schedule.getRoom().sc.getSeatNum() +
                            "  观影时间:" + schedule.getTime());
                    schedule.getRoom().sc.seatingInformation();
                }
            }
            if (!found) {
                System.out.println("未进行该安排！");
            }
        } else {
            System.out.println("无权限，请先进行登录！");
        }
    }

    @Override
    public void setScreenRoom(Cinema cinema, ScreenRoom room) {
        System.out.println("售票员无权限进行设置观影院操作！");
    }

    @Override
    public void addMovie(Cinema cinema, MovieSchedule schedule) {
        System.out.println("售票员无权限进行排片操作！");
    }

    @Override
    public void removeMovie(Cinema cinema, MovieSchedule schedule) {
        System.out.println("售票员无权限进行排片操作！");
    }
}
